<?php

namespace App\Admin\Controllers;

use App\Helper\Utils as Utils;
use App\Http\Controllers\Controller;
use App\Models\STeaScheduleInfo;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class TeaScheduleController extends Controller {
	use HasResourceActions;

	/**
	 * Index interface.
	 *
	 * @param Content $content
	 * @return Content
	 */
	public function index(Content $content) {
		return $content
			->header('外教时间表')
			->description('列表')
			->body($this->grid());
	}

	/**
	 * Show interface.
	 *
	 * @param mixed $id
	 * @param Content $content
	 * @return Content
	 */
	public function show($id, Content $content) {
		return $content
			->header('外教时间表')
			->description('详情')
			->body($this->detail($id));
	}

	/**
	 * Edit interface.
	 *
	 * @param mixed $id
	 * @param Content $content
	 * @return Content
	 */
	public function edit($id, Content $content) {
		return $content
			->header('外教时间表')
			->description('编辑')
			->body($this->form()->edit($id));
	}

	/**
	 * Create interface.
	 *
	 * @param Content $content
	 * @return Content
	 */
	public function create(Content $content) {
		return $content
			->header('外教时间表')
			->description('新增')
			->body($this->form());
	}

	/**
	 * Make a grid builder.
	 *
	 * @return Grid
	 */
	protected function grid() {
		$grid = new Grid(new STeaScheduleInfo);

		$grid->id('Id')->sortable();
		// $grid->teacher_id('Teacher id');
		$grid->teachers()->name("外教");
		$grid->date_time('日期');

		$grid->time_0800('08:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_0830('08:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_0900('09:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_0930('09:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1000('10:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1030('10:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1100('11:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1130('11:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1200('12:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1230('12:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1300('13:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1330('13:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1400('14:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1430('14:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1500('15:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1530('15:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1600('16:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1630('16:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1700('17:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1730('17:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1800('18:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1830('18:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1900('19:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_1930('19:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_2000('20:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_2030('20:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_2100('21:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_2130('21:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_2200('22:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_2230('22:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_2300('23:00')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		$grid->time_2330('23:30')->display(function ($t) {
			return Utils::getTeaScheduleStatus($t);
		});
		// $grid->created_at('Created at');
		// $grid->updated_at('更新时间');
		$grid->disableActions();
		$grid->disableCreateButton();
		$grid->disableExport();
		$grid->disableRowSelector();
		$grid->filter(function ($filter) {
			$filter->between('date_time', '日期')->date();

			$filter->where(function ($query) {

				$query->whereHas('teachers', function ($query) {
					$query->where('name', 'like', "%{$this->input}%");
				});

			}, '外教');

			// 在这里添加字段过滤器
			// $filter->like('name', 'name');

		});
		// $grid->actions(function ($actions) {
		//     $actions->disableDelete();
		//     $actions->disableEdit();
		//     $actions->disableView();
		// });
		return $grid;
	}

	/**
	 * Make a show builder.
	 *
	 * @param mixed $id
	 * @return Show
	 */
	protected function detail($id) {
		$show = new Show(STeaScheduleInfo::findOrFail($id));

		$show->id('Id');
		// $show->teacher_id('Teacher id');
		$show->date_time('日期');
		$show->time_0800('08:00');
		$show->time_0830('08:30');
		$show->time_0900('09:00');
		$show->time_0930('09:30');
		$show->time_1000('10:00');
		$show->time_1030('10:30');
		$show->time_1100('11:00');
		$show->time_1130('11:30');
		$show->time_1200('12:00');
		$show->time_1230('12:30');
		$show->time_1300('13:00');
		$show->time_1330('13:30');
		$show->time_1400('14:00');
		$show->time_1430('14:30');
		$show->time_1500('15:00');
		$show->time_1530('15:30');
		$show->time_1600('16:00');
		$show->time_1630('16:30');
		$show->time_1700('17:00');
		$show->time_1730('17:30');
		$show->time_1800('18:00');
		$show->time_1830('18:30');
		$show->time_1900('19:00');
		$show->time_1930('19:30');
		$show->time_2000('20:00');
		$show->time_2030('20:30');
		$show->time_2100('21:00');
		$show->time_2130('21:30');
		$show->time_2200('22:00');
		$show->time_2230('22:30');
		$show->time_2300('23:00');
		$show->time_2330('23:30');
		// $show->created_at('Created at');
		$show->updated_at('更新时间');
		// $show->deleted_at('Deleted at');

		return $show;
	}

	/**
	 * Make a form builder.
	 *
	 * @return Form
	 */
	protected function form() {
		$form = new Form(new STeaScheduleInfo);

		$form->number('teacher_id', 'Teacher id');
		$form->date('date_time', 'Date time')->default(date('Y-m-d'));
		$form->number('time_0800', 'Time 0800');
		$form->number('time_0830', 'Time 0830');
		$form->number('time_0900', 'Time 0900');
		$form->number('time_0930', 'Time 0930');
		$form->number('time_1000', 'Time 1000');
		$form->number('time_1030', 'Time 1030');
		$form->number('time_1100', 'Time 1100');
		$form->number('time_1130', 'Time 1130');
		$form->number('time_1200', 'Time 1200');
		$form->number('time_1230', 'Time 1230');
		$form->number('time_1300', 'Time 1300');
		$form->number('time_1330', 'Time 1330');
		$form->number('time_1400', 'Time 1400');
		$form->number('time_1430', 'Time 1430');
		$form->number('time_1500', 'Time 1500');
		$form->number('time_1530', 'Time 1530');
		$form->number('time_1600', 'Time 1600');
		$form->number('time_1630', 'Time 1630');
		$form->number('time_1700', 'Time 1700');
		$form->number('time_1730', 'Time 1730');
		$form->number('time_1800', 'Time 1800');
		$form->number('time_1830', 'Time 1830');
		$form->number('time_1900', 'Time 1900');
		$form->number('time_1930', 'Time 1930');
		$form->number('time_2000', 'Time 2000');
		$form->number('time_2030', 'Time 2030');
		$form->number('time_2100', 'Time 2100');
		$form->number('time_2130', 'Time 2130');
		$form->number('time_2200', 'Time 2200');
		$form->number('time_2230', 'Time 2230');
		$form->number('time_2300', 'Time 2300');
		$form->number('time_2330', 'Time 2330');

		return $form;
	}
}
